<template>
  <div class="rank">
    <div class="rank_title">{{ title }}</div>
    <div class="th">
      <div>{{ th[0] }}</div>
      <div>{{ th[1] }}</div>
      <div>{{ th[2] }}</div>
    </div>
    <div class="wrapper" :id="title">
      <ul class="content">
        <li
          class="item"
          v-for="(item, index) in listData"
          :key="index"
        >
          <div v-if="item.redyellowblack === 1" class="rank_img">
            <img src="../assets/icon_bg.png">
            <div>{{ item.rank }}</div>
          </div>
          <div v-else class="rank_num">{{ item.rank || index + 1 }}</div>
          <div v-if="item.redyellowblack === 1" class="bar red">
            <div class="name">{{ item.streets || item.department || item.unit || item.township || item.town }}</div>
            <div class="score">{{ item.allNumber }}</div>
          </div>
          <div v-else-if="item.redyellowblack === 2" class="bar yellow">
            <div class="name">{{ item.streets || item.department || item.unit || item.township || item.town }}</div>
            <div class="score">{{ item.allNumber }}</div>
          </div>
          <div v-else-if="item.redyellowblack === 3" class="bar black">
            <div class="name">{{ item.streets || item.department || item.unit || item.township || item.town }}</div>
            <div class="score">{{ item.allNumber }}</div>
          </div>
          <div v-else class="bar">
            <div class="name">{{ item.streets || item.department || item.unit || item.township || item.town }}</div>
            <div class="score">{{ item.allNumber }}</div>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import BetterScroll from 'better-scroll';

export default {
  name: 'Ranklist',
  data() {
    return {
    };
  },
  props: ['listData', 'title', 'th'],
  mounted() {
    let self = this;
    // 更好的滚动
    new BetterScroll('#' + self.title, {
      // movable: true,
      zoom: true,
      mouseWheel: true,
    });
  },
};
</script>

<style>
.wrapper {
  height: 35vw;
  overflow: hidden;
  border: 2px solid rgb(51, 113, 228);
  border-radius: 1vw;
  background-color: rgba(73, 150, 214, 0.096);
}
.wrapper .content {
  padding: 1vw;
  box-sizing: border-box;
}
.rank {
  height: 20vw;
}
.rank_title {
  text-align: center;
  color: rgb(51, 113, 228);
  font-size: 1.4vw;
  font-weight: bold;
}
.th {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1vw;
  padding: 0 0.4vw;
  box-sizing: border-box;
  margin-bottom: 0.2vw;
}
.item {
  height: 2.5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.rank_img {
  width: 1.5vw;
  position: relative;
  color: #fff;
  font-size: 1vw;
  top: -0.2vw;
}
.rank_img img {
  width: 1.5vw;
  vertical-align: middle;
}
.rank_img div {
  position: absolute;
  top: 48%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.rank_num {
  width: 1.4vw;
  height: 1.4vw;
  text-align: center;
  line-height: 1.4vw;
  color: #fff;
  font-size: 1vw;
  border-radius: 50%;
  background-color: rgb(75, 142, 219);
}
.bar {
  color: #333;
  font-size: 1vw;
  width: 88%;
  height: 1.4vw;
  border-radius: 1vw;
  background-color: rgb(187, 197, 193);
  padding: 0 1vw 0 1.5vw;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bar.red {
  color: #fff;
  background-color: rgb(211, 65, 76);
}
.bar.yellow {
  color: #fff;
  background-color: rgb(241, 162, 26);
}
.bar.black {
  color: #fff;
  background-color: #333;
}
</style>
